package gamehistory.player;

import gamehistory.utils.xml.XMLModel;

/**
 * 
 * @author Brent Kersanske
 *
 */
public class PlayerRoundModel extends XMLModel {
	
	public static final String NUMBER	     = "number";
	public static final String ACCOUNT_VALUE = "accountValue";
	public static final String NUM_ACCEPTS 	 = "numAccepts";
	public static final String NUM_OFFERS    = "numOffers";
	public static final String NUM_REOFFERS  = "numReoffers";
	public static final String NUM_PROVIDES  = "numProvides";
	public static final String NUM_SOLVES    = "numSolves";
	
	private int roundNumber;
	private int numAccepts;
	private int numOffers;
	private int numReoffers;
	private int numProvides;
	private int numSolves;
	private double accountValue;
	
	/**
	 * Constructor.
	 * @param roundNumber
	 * @param accountStartValue
	 */
	public PlayerRoundModel(int roundNumber, double accountStartValue) {
		super("round");
		this.roundNumber  = roundNumber;
		this.accountValue = accountStartValue;
		resetCounts();
	}
	
	public static PlayerRoundModel getStartingRound() {
		return new PlayerRoundModel(0, 100.0d);
	}
	
	private void resetCounts() {
		this.numAccepts	  = 0;
		this.numOffers	  = 0;
		this.numReoffers  = 0;
		this.numProvides  = 0;
		this.numSolves    = 0;
	}
	
	public void updateNumberOfAccepts(int numberOfAcceptsToAdd) {
		this.numAccepts += numberOfAcceptsToAdd;
	}
	
	public void updateNumberOfOffers(int numberOfOffersToAdd) {
		this.numOffers += numberOfOffersToAdd;
	}
	
	public void updateNumberOfReoffers(int numberOfReoffersToAdd) {
		this.numReoffers += numberOfReoffersToAdd;
	}
	
	public void updateNumberOfProvides(int numberOfProvidesToAdd) {
		this.numProvides += numberOfProvidesToAdd;
	}
	
	public void updateNumberOfSolves(int numberOfSolvesToAdd) {
		this.numSolves += numberOfSolvesToAdd;
	}
	
	public void updateAccountValue(double accountValue) {
		this.accountValue = accountValue;
	}
	
	public void buildModel() {
		addAttribute(NUMBER,        String.valueOf(this.roundNumber));
		addAttribute(ACCOUNT_VALUE, String.valueOf(this.accountValue));
		addAttribute(NUM_ACCEPTS,   String.valueOf(this.numAccepts));
		addAttribute(NUM_OFFERS,    String.valueOf(this.numOffers));
		addAttribute(NUM_REOFFERS,  String.valueOf(this.numReoffers));
		addAttribute(NUM_PROVIDES,  String.valueOf(this.numProvides));
		addAttribute(NUM_SOLVES,    String.valueOf(this.numSolves));
	}
}
